// src/books/book.controller.ts
import { Controller, Get, Post,  Put, Delete,  Param, Body, ParseUUIDPipe } from '@nestjs/common';
import { BookService } from '../service/book.service';
import { Book, BookCreateDto, BookUpdateDto } from '../dto/book.dto';

@Controller('books')
export class BookController {
  constructor(private readonly bookService: BookService) {}

  // GET /books - 获取所有图书
  @Get()
  getAllBooks(): Book[] {
    return this.bookService.getAllBooks();
  }

  // GET /books/:id - 根据ID获取图书
  @Get(':id')
  getBookById(@Param('id') id: string): Book {
    return this.bookService.getBookById(id);
  }

  // POST /books - 创建新图书
  @Post()
  createBook(@Body() bookData: BookCreateDto): Book {
    return this.bookService.createBook(bookData);
  }

  // PUT /books/:id - 更新图书信息
  @Put(':id')
  updateBook(
    @Param('id') id: string,
    @Body() updateData: BookUpdateDto
  ): Book {
    return this.bookService.updateBook(id, updateData);
  }

  // DELETE /books/:id - 删除图书
  @Delete(':id')
  deleteBook(@Param('id') id: string): { message: string } {
    this.bookService.deleteBook(id);
    return { message: '图书删除成功' };
  }
}